package com.heima.wemedia;

import com.heima.file.service.FileStorageService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * @作者 itcast
 * @创建日期 2021/9/22 14:44
 **/
@SpringBootTest
@RunWith(SpringRunner.class)
public class OssUpload {

    @Autowired
    FileStorageService fileStorageService;

    @Value("${file.oss.prefix}")
    String prefix;

    @Value("${file.oss.web-site}")
    String webSite;

    @Test
    public void upload() throws FileNotFoundException { // 跑起来     CRUD   controller  service  dao
        FileInputStream fileInputStream = new FileInputStream("D:\\picture\\mv004.jpg");
        // 文件在oss中的完整路径
        String store = fileStorageService.store(prefix, "mv004.jpg", fileInputStream);
        System.out.println(webSite + store);
    }

    @Test
    public void delete() throws FileNotFoundException { // 跑起来     CRUD   controller  service  dao
        fileStorageService.delete("material/2021/9/20210922/mv004.jpg");
    }
}
